package com.hongsheng.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hongsheng.mapper.DriverMapper;
import com.hongsheng.pojo.Driver;
import com.hongsheng.service.DriverService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName:DriverServiceImpl
 * Description:
 *
 * @Author: 曾晋冠
 * @Version: 2022.3.2
 * @Create: 2023/8/10 - 17:09
 */
@Service
public class DriverServiceImpl extends ServiceImpl<DriverMapper, Driver> implements DriverService {
    @Resource
    private DriverMapper driverMapper;

    /**
     * 查询全部
     * @return
     */
    @Override
    public List<Driver> findAllDriver(){
        return driverMapper.findAllDriver();
    }

    /**
     * 添加
     * @param driver
     * @return
     */

    @Override
    public Boolean addDriver(Driver driver) {
        if (driver.getType().equals("大型货车")) {
            driver.setCarLoad(30000.0);
            driver.setSize(60.0);
        } else if (driver.getType().equals("中型货车")) {
            driver.setCarLoad(20000.0);
            driver.setSize(40.0);
        } else if (driver.getType().equals("小型货车")) {
            driver.setCarLoad(10000.0);
            driver.setSize(20.0);
        }
        if (driver.getStatus()==null){
            driver.setStatus(0);
        }
        return driverMapper.addDriver(driver);
    }

    /**
     * 修改
     * @param driver
     * @return
     */
    @Override
    public Boolean updateDriver(Driver driver) {
        return driverMapper.updateDriver(driver);
    }
    @Override
    public Boolean setStuDr(Driver driver){
        Integer integer = driverMapper.setDriverStu(driver);
        return integer>0;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public Boolean deleteDriver(Integer id) {
        return driverMapper.deleteDriver(id);
    }

    @Override
    public List<Driver> findFreeDriver() {
        return driverMapper.findFreeDriver();
    }
    @Override
    public Driver findAllById(Integer id) {
        return driverMapper.findAllById(id);
    }

    @Override
    public PageInfo<Driver> getPageDriver(Integer currentPage, Integer pageSize, Driver driver) {
        PageHelper.startPage(currentPage,pageSize);
        if (driver.getDriverName()==null || driver.getDriverName().isEmpty()){
        }else {
            driver.setDriverName("%"+driver.getDriverName()+"%");
        }
        List<Driver> pageDriver = driverMapper.getPageDriver(driver.getDriverName(),driver.getType(),driver.getStatus());
        return new PageInfo<Driver>(pageDriver);
    }

    @Override
    public Boolean findStatus(Integer id) {
        Integer status = driverMapper.findStatus(id);
        if (status==0){
            return true;
        }
        return false;
    }

    @Override
    public Boolean findPhone(String driverPhone) {
        Boolean phone = driverMapper.findPhone(driverPhone);
        if (phone==null){
            return true;
        }else {
            return false;
        }
    }

}
